import { Component, OnInit } from '@angular/core';
import { NavController, ModalController, ActionSheetController, PopoverController } from '@ionic/angular';
import { CacheService } from '@services/cache.service';
import { DataService } from '@services/data.service';
import { PicUploadService } from '@services/picUpload.service';
import { PopoverPage } from './popover/popover';

@Component({
    selector: 'personal-manager',
    templateUrl: 'personal-manager.html',
    styleUrls: ['personal-manager.scss']
})

export class PersonalManagerPage implements OnInit {
    user;
    title;
    person;
    punchStatus;
    selectTabIndex;
    address;
    constructor(public navCtrl: NavController,
        public modalCtrl: ModalController,
        public actionSheetCtrl: ActionSheetController,
        public dataService: DataService,
        public cache: CacheService,
        private picUploadService: PicUploadService,
        private popoverCtrl: PopoverController
    ) {
    }

    ngOnInit() {
        this.user = this.cache.userinfo;

        // 默认为个人页
        this.selectTabIndex = 0;

        // 先假定是管理层
        this.user.isLeader = this.user.IsDeptUser;
        const titles = ['人员管理', '个人管理'];
        this.title = this.user.isLeader ? titles[0] : titles[1];
        this.person = {};
        const punchStatusList = ['未在岗', '公司', '外出'];
        this.punchStatus = punchStatusList[0];
    }

    ionViewWillEnter() {
        this.setHeadAndBack();
    }

    setHeadAndBack() {
        this.picUploadService.getAvatar().subscribe(imgdata => {
            if (imgdata.isDefault) {
                this.person.imgStyle = { 'background': '#1fb5ff' };
            } else {
                this.person.imgStyle = { 'background-image': 'url(' + imgdata.url + ')' };
            }
            this.person.imgStyle = { 'background-image': 'url(' + imgdata.url + ')' };
        });
    }
    // 个人与团队切换
    selectTab(index) {
        this.selectTabIndex = index;
    }

    // showPopover() {
    //     const data = {};
    //     const popover = this.popoverCtrl.create(PopoverPage, data, { cssClass: 'personal-popover' });
    //     popover.present();
    // }
    showPopover() { }
}
